<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SplitContainer Demo</title>
     <style type="text/css">
            @import "../dojo/dojo-release-1.0.0/dijit/themes/tundra/tundra.css";
            @import "../dojo/dojo-release-1.0.0/dojo/resources/dojo.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/tundraGrid.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/Grid.css";
            @import "../js/wlProject.css";
			@import "../js/dijitTests.css";
			@import "../dojo/dojo-release-1.0.0/dojox/layout/tests/_expando.css";
	
      </style>
      <script type="text/javascript" src="../dojo/dojo-release-1.0.0/dojo/dojo.js"  
                djConfig="parseOnLoad: true, isDebug: true,locale: 'zh-cn', extraLocale: ['zh-TW', 'fr']"></script>
      <script>
    
            dojo.require("dojo.data.ItemFileWriteStore");
			dojo.require("dijit.layout.BorderContainer");
            dojo.require("dojox.layout.ExpandoPane");
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.Tree");
            dojo.require("dojo.parser");
            dojo.require("dijit._tree.dndSource");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.Button");
            dojo.require("dojox.grid.Grid");
            dojo.require("dojox.grid._data.model");
            dojo.require("dojo.i18n");
            dojo.require("dojox.validate._base");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.TextBox");
            dojo.require("dijit.form.FilteringSelect");
            dojo.require("dojox.grid._data.dijitEditors");
            
            dojo.registerModulePath("mydojo", "../../../js/mydojo");
            dojo.require("mydojo.FilteringSelect");
            dojo.require("mydojo.ValidationTextBox");
            
     </script>
        
    <script type="text/javascript" src="../js/soapclient.js"></script>
    <script type="text/javascript" src="../js/wlProject.js"></script>
	<script type="text/javascript" src="../js/peoplevo.js"></script>
	<script type="text/javascript" src="../js/orgavo.js"></script>
	<script type="text/javascript" src="../js/orgaPeoplevo.js"></script>
    <script type="text/javascript" >


        var url = getUrl()+ "services/OrgaPeopleManageService";
        var data =new Array();
        var poptarts ={ label:'name',identifier:'eId',items:data};
        var popStore = new dojo.data.ItemFileWriteStore({data: poptarts});
		 
        var orderBy='0';
        var deletedata2 =new Array();
          //var itemt="区域";
        var selectNodeIdentity=0;//单击的树节点ID
        var selectNode;
          
		var griddata =  new Array();
		var deletedata=new Array();
		var querydata =  new Array();
		var queryvo=new PeopleVO(); //   
		var totalCount=0 ;
		var totalpage=0 ;
		var pagenumber=1;
		var pagesize=10;
		var model = new dojox.grid.data.Table(null, griddata);
		var editfield =[{type: 'dojox.GridRowView', width: '20px' },{
                                 cells: [ [
                                            //{name: '????', width: 3, get:getChoise},
                                           { name: 'choise', width: 3,field:0, styles: 'text-align: center;', editor: dojox.grid.editors.Bool },//
                                           { name: 'No.', width: 2, styles: 'text-align: center;', get: function(inRowIndex){ return inRowIndex+1;} }//,
                                          //{name: 'orgaSno', field: 2,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                             ,   {name: 'orgaName', field: 3,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                             ,   {name: 'orgaCode', field: 4,width: 10, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                                             ,   {name: 'remark', field: 5,width: 10, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                                             ,   {name: 'orgaState', field: 6,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                         ] ]
                           }];

function call_funUpd() {
       //var s = grid.selection.getSelected();
       //var  d=new DateTimeQuery();
       //var n=new NumberQuery();
       var sall=grid.model.data;
       for(var i=0;i<sall.length;i++){
       if(sall[i][0]==true){
         var passAll=0;
         var thisCell=sall[i];
         var padd = new SOAPClientParameters2();
         var vobject=new OrgaInfoVOJs();
         vobject.id=thisCell[1];
         vobject.orgaSno=thisCell[2];		 
              if(dojox.validate.isText(thisCell[3], {minlength: 1})){vobject.orgaName=thisCell[3];
             }else{grid.getCell(3).getNode(i).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>"; passAll=1;}//not null
 
               vobject.orgaCode=thisCell[4];
 
               vobject.remark=thisCell[5];
 
              if(dojox.validate.isText(thisCell[6], {minlength: 1})){vobject.orgaState=thisCell[6];
             }else{grid.getCell(6).getNode(i).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>"; passAll=1;}//not null
        if(passAll==0){
             if(thisCell[1]==0){//create new row
			    vobject.orgaSno=selectNode.item['type'];   
				if(selectNode.item['type']==undefined)vobject.orgaSno="";
                padd.add('OrgaInfoVO',vobject);
                SOAPClient.invoke(url, "createOrgaInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                grid.model.setDatum(ul,i,1);
				for(var t in selectNode){
					console.log(t+":"+selectNode[t]);
				}
				//alert(selectNode.item);
				if(selectNode.label=="部门"){
					addTreeNode(null,vobject.orgaName,vobject.orgaSno,ul);
				}else{
					addTreeNode(selectNode.item,vobject.orgaName,vobject.orgaSno,ul);}
                });
	         }else{//modify row
                padd.add('OrgaInfoVO',vobject);
                SOAPClient.invoke(url, "updateOrgaInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                });
				setTreeNode(vobject.id,vobject.orgaName,vobject.orgaSno);
	         }
        } }}//for
          for(var i=0;i<deletedata.length;i++){
               var pdel = new SOAPClientParameters();      
               pdel.add('id',deletedata[i]);
               SOAPClient.invoke(url, "deleteOrgaInfo", pdel, false,  function GetEnu_callBack(ul, soapResponse){
	             delTreeNode(deletedata[i]);
	           });
          }
          deletedata=new Array();
          dojo.byId("rowCount").innerHTML = 'saved'; 
//submit delete end          
 }

 function removeSelectedRowsGrid(){
       //var s = grid.selection.getSelected();
       var s= new Array();
       var sall=grid.model.data;
       for(var i=0;i<sall.length;i++){
       if(sall[i][0]==true){
          s.push(i);
          var thisCell=sall[i];
          if(thisCell[1]!=0){//the row which will be deleted
            deletedata.splice(deletedata.length,0,thisCell[1]);
       }}}
      grid.model.remove(s);//grid.removeSelectedRows();
 }

   function addTreeNode(pid,orgaName,orgaSno,id){
				var pInfo = {
								parent: pid,		
								attribute: "children"	
							};
               popStore.newItem({name: orgaName,type:orgaSno,eId:id}, pInfo);
         }  
	function delTreeNode(id){
		var node = dijit.byId("tree")._itemNodeMap[id];
		popStore.deleteItem(node.item);//同时删除所有子节点
	  }  
	  
	function setTreeNode(id,orgaName,orgaSno){
		var node = dijit.byId("tree")._itemNodeMap[id];
		//alert("placeName:"+placeName);
		//alert("placeType:"+placeType);
		popStore.setValue(node.item,"name",orgaName);         
		popStore.setValue(node.item,"type",orgaSno);      
		node.setLabelNode(orgaName);
		 }  
addRow = function(){
          	grid.addRow([false,0,"","","","",""],grid.model.getRowCount());
	        } 
                          
function querybutton(){
              //var p = new SOAPClientParameters2();
              var d,n;
              var validstate=0;
              //queryvo.id=0 ;
              queryvo=new OrgaInfoVOJs();
              if(queryorgaSno.getDisplayedValue()!="")queryvo.orgaSno=queryorgaSno.getDisplayedValue();//
              if(queryorgaName.getDisplayedValue()!="")queryvo.orgaName=queryorgaName.getDisplayedValue();//
              if(queryorgaCode.getDisplayedValue()!="")queryvo.orgaCode=queryorgaCode.getDisplayedValue();//
              if(queryremark.getDisplayedValue()!="")queryvo.remark=queryremark.getDisplayedValue();//
              if(queryorgaState.getDisplayedValue()!="")queryvo.orgaState=queryorgaState.getDisplayedValue();//
        if(validstate==0){
              pagenumber=1;
              getOrgaVO(queryvo,pagenumber,pagesize,'0');
              if(totalpage>1){dijit.byId("but7").setDisabled(false);}else{dijit.byId("but7").setDisabled(true);}
             }      
       }

 querydis = function(){
               querydisplay("queryDiv");
            }
 
 


function getOrgaVO(queryvo,pagenumber,pagesize,orderBy){

      var pu = new SOAPClientParameters2();
      pu.add('OrgaInfoVO',queryvo) ;
      pu.add('pageNumber',pagenumber) ;
	    pu.add('pageSize',pagesize) ;
	    pu.add('orderBy',orderBy) ;
      SOAPClient.invoke(url,"getOrgaInfo", pu, false,  function GetEnu_callBack(ul, soapResponse){      
           querydata=OrgaInfoVOtoArray_fun(ul,true);
           totalCount=ul[ul.length-1]["ns:id"]; 
           totalpage=Math.ceil(new Number(totalCount)/pagesize);
           document.getElementById("rowCount").innerHTML=" "+pagenumber+" / "+totalpage+" / "+totalCount+" " ;
      }); 
      querydata.splice(querydata.length-1,1);
      model.setData(querydata);
      //dijit.byId("grid").updateRowCount(querydata.length); 
 }
          
        
        
  var myModel = new dijit.tree.ForestStoreModel({
  				store: popStore,
  				rootId: "0",
  				rootLabel: "部门",
  				childrenAttrs: ["children"]
  			});        
  var _tree=dijit.byId("tree");      
  function getTreeNodes(orgaSno,chitem,layerInt,layerSum){//首层layerInt=0
           var pl = new SOAPClientParameters();
           pl.add('orgaSno',orgaSno) ;
           pl.add('orgaName','%') ;
           pl.add('orgaCode','%') ;
           pl.add('remark','%') ;
           pl.add('orgaState','%') ;
           pl.add('id',0) ;
           SOAPClient.invoke(url, "getOrgaInfoVO", pl, false,  function GetEnu_callBack(ul, soapResponse){
               var pInfo = {
                   					parent: chitem,		
                   					attribute: "children"	
                   		};
               if(ul!=null && ul.length>0 ){
                     for(var i = 0; i < ul.length; i++){		
                                  var ulo=ul[i];
                                  var newitem=popStore.newItem({name: ulo["ns:orgaName"],type:ulo["ns:orgaSno"] ,eId:ulo["ns:id"]}, pInfo);//haveChild=0初始，1有子结点，2无子结点
                                  if(layerInt<layerSum)getTreeNodes(ulo["ns:orgaSno"]+"___",newitem,layerInt+1,layerSum);
                              }
                      if(chitem!=null){
                            popStore.setValue(chitem,"haveChild","1"); 
                            var node = dijit.byId("tree")._itemNodeMap[chitem.eId];
                            node._updateItemClasses(node.item);
                            //node.expand();       
                      }
                }else{
                    popStore.setValue(chitem,"haveChild","2");  
                }       
          });}
   function expandAllChildrenNode(tree,treeNode,layerInt,layerSum){
		       var childrenArray=treeNode.getChildren();
          if(childrenArray!=null&&childrenArray.length>0)tree._expandNode(treeNode);
         
          
          for (var i=0; i<childrenArray.length; i++){	
             if(layerInt<layerSum) expandAllChildrenNode(tree,childrenArray[i],layerInt+1,layerSum);
             if(layerInt==layerSum)childrenArray[i]._updateItemClasses(childrenArray[i].item);
          }
        }              
        

   
   function init(){
        //添加分类第一层结点        
		    var _tree=dijit.byId("tree");  
		    getTreeNodes("___",null,0,2);//001,002,003...
		    expandAllChildrenNode(_tree,_tree.rootNode,0,1);

    dojo.connect(dijit.byId("tree"), "_onExpandoClick", function(message){
                       var node = message.node;
                       var ch2node=node.getChildren();
                       for (var i=0; i<ch2node.length; i++){	
                       if(ch2node[i].getChildren().length==0&&ch2node[i].item.haveChild=="0"){
                         var ch2item =ch2node[i].item;
                         getTreeNodes(ch2item.type+"___",ch2item,0,1);
                       }
                      
                      }
             	 
            });   
//查询列表----begin
             dojo.connect(_tree, "onClick", function(item,node){
             //判断哪个tab在显示
             	    selectNode=node;
                    selectNodeIdentity = _tree.store.getIdentity(item);
                    var p0 = new SOAPClientParameters();
              if(mainTabContainer.selectedChildWidget.id=='peoplePane'){
                    var OrgaPeoplequeryvo=new OrgaPeopleVOJs();
                    var orgaquervo= new OrgaInfoVOJs();
                    orgaquervo.id=item["eId"];
                    OrgaPeoplequeryvo.orga=orgaquervo;
                    getOrgaPeopleVO(OrgaPeoplequeryvo,pagenumber,pagesize,orderBy)
					grid.selection.clear();
					deletedata =new Array();
                /* var titles=node.item["name"];
                var parentNodes=node;
                while(parentNodes.getParent()!= null&& parentNodes.getParent()["id"]!="tree"){
                      parentNodes=parentNodes.getParent();
                      titles=parentNodes.item["name"]+' '+titles;
                };
                dojo.byId("placetitle").innerHTML = titles +"";*/
             }else if(mainTabContainer.selectedChildWidget.id=='orgaPane'){
                    //var orgaquervo= new OrgaInfoVOJs();
					
                    queryvo.orgaSno=item['type']+"___";
					if(item['type']==undefined)queryvo.orgaSno="___";
                    getOrgaVO(queryvo,pagenumber,pagesize,orderBy);
                    
                grid.selection.clear();
				deletedata =new Array();
              }
          });  
           //查询列表----end
  }//END INIT
            
           dojo.addOnLoad(init);
           

          //查询按钮
          
          

             
</script>
</head>
<body class="tundra">
	<div id="bc" style="width:100%; height:100%;" dojoType="dijit.layout.BorderContainer">
	    <div dojoType="dojox.layout.ExpandoPane" splitter="true" duration="125" region="left" title="Left Section" id="leftPane" maxWidth="275" style="width: 275px; background: #fafafa;">
			<div id="tree" showRoot="true" persist="false" dojoType="dijit.Tree"  store="popStore" labelAttr="name"  childrenAttr="children"  model="myModel" ></div>		
		</div>
		<div dojoType="dijit.layout.TabContainer" region="center" jsId="mainTabContainer" id="mainTabContainer">
			<div dojoType="dijit.layout.ContentPane" id="orgaPane" title="部门维护">部门维护
				<div id="queryDiv" style="margin-right: 30px;  height: 460px; display:none;" >
	              <table align="center" width=100% class="queryTable"  >
	                <tr ><td align="center" style="{width:11%}">Please input criterial:</td>
	                <td style="{width:22%}" ></td>
	                <td style="{width:11%}"></td>
	                <td style="{width:6%}" ></td>
	                <td style="{width:11%}" ></td>
	                <td style="{width:6%}" ></td>
	                <td style="{width:11%}"></td>
	                <td style="{width:22%}"></td></tr> 
	                <tr ><td align="center" style="{width:11%}"></td>
	                <td style="{width:22%}" ></td>
	                <td style="{width:11%}"></td>
	                <td style="{width:6%}" ></td>
	                <td style="{width:11%}" ></td>
	                <td style="{width:6%}" ></td>
	                <td style="{width:11%}"></td>
	                <td style="{width:22%}"></td></tr>  
	                <tr>
	                    <td align="right"  >orgaSno:</td>
	                    <td align="left"  ><input type="text" class="editerInput"  id="queryorgaSno"  jsId="queryorgaSno"   dojoType="dijit.form.TextBox"  /></td>
	                    <td align="right"  >orgaName:</td>
	                    <td align="left"  colspan="3" ><input type="text" class="editerInput"  id="queryorgaName"  jsId="queryorgaName"   dojoType="dijit.form.TextBox"  /></td>  
	                    <td align="right"  >orgaCode:</td>
	                    <td align="left"  ><input type="text" class="editerInput"  id="queryorgaCode"  jsId="queryorgaCode"   dojoType="dijit.form.TextBox"  /></td>  
					</tr>
	                <tr>
	                    <td align="right"  >remark:</td>
	                    <td align="left"  ><input type="text" class="editerInput"  id="queryremark"  jsId="queryremark"   dojoType="dijit.form.TextBox"  /></td>
	                    <td align="right"  >orgaState:</td>
	                    <td align="left"  colspan="3" ><input type="text" class="editerInput"  id="queryorgaState"  jsId="queryorgaState"   dojoType="dijit.form.TextBox"  /></td>  
		
					<tr align="center"><td></td>
			           <td colspan="2"><a onclick="querybutton();"><img src="../image/332.gif" height="20" width="20" border="0">OK</a></td>
			           <td colspan="3"></td><td colspan="2"></td></tr>
		          </table>
				</div>
				<div align="right">
				 &nbsp;&nbsp;&nbsp;
					 <button dojoType="dijit.form.Button" onclick="addRow();" iconClass="addIcon" >add</button>
					 <button dojoType="dijit.form.Button" onclick="removeSelectedRowsGrid();" iconClass="delIcon" >delete</button>
					 <button dojoType="dijit.form.Button" id="but3" jsId="but3" onclick="call_funUpd();"  iconClass="saveIcon">save</button>
					 <button dojoType="dijit.form.Button" onclick="querydis();" iconClass="queryIcon" >query</button>
				  
				</div>    
			    <div style="{height:90%;width:100%}"  >
			         <div id="grid"  dojoType="dojox.Grid" autoWidth="false"  jsId="grid"	model="model"  structure="editfield" singleClickEdit="true" ></div>
				</div> 
				<div align="right" ><span id="rowCount"></span>
			        <button dojoType="dijit.form.myButton" onclick="upPage();"  id="but6" disabled='true' jsId="but6" iconClass="upPageIcon" >pageup</button><!--span dojoType="dijit.Tooltip" connectId="but6">pageup</span-->
			        <button dojoType="dijit.form.myButton" onclick="downPage();" id="but7" disabled='true' jsId="but7" iconClass="downPageIcon" >pagedown</button><!--span dojoType="dijit.Tooltip" connectId="but7">pagedown</span-->
			        <div  dojoType="dijit.form.myDropDownButton" iconClass="pageIcon" ><span>pageNumber</span>
			  			  <div dojoType="dijit.Menu">
							  <div dojoType="dijit.MenuItem" label="10"  iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
							  <div dojoType="dijit.MenuItem"  label="30" iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
					      <div dojoType="dijit.MenuItem"  label="50" iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
								<div dojoType="dijit.MenuItem"  label="100" iconClass="toPageIcon"	onClick="pageSizeChange(this.label);"></div>
								<div dojoType="dijit.MenuItem"  label="noPage" iconClass="noPageIcon"	onClick="allpage();"></div>
					      </div><!--span dojoType="dijit.Tooltip" connectId="668"></span-->
			        </div>
					<div  dojoType="dijit.form.myDropDownButton" iconClass="pageStyleIcon"><span>pageStyle</span>
					<div dojoType="dijit.Menu">
					 <div dojoType="dijit.MenuItem"  iconClass="rowIcon"		label="row"	onClick="pageStyle(this.label);"></div>
					 <div dojoType="dijit.MenuItem"  iconClass="colIcon"		label="col"	onClick="pageStyle(this.label);"></div>
				    </div></div>
				</div>     
			
		</div>
			
		<div dojoType="dijit.layout.ContentPane" id="peoplePane" title="人员查询">人员查询</div>
		</div>
	</div>	
</body></html>
